//
//  LDSound.h
//  
//	
//  Created by snowymydog on 10/06/10.
//  Copyright LazyDog 2010. All rights reserved.
//

#import "LDSound.h"
//#import <OpenGLES/ES1/glext.h>
//#import "OpenGL_Internal.h"
//#import <UIKit/UIKit.h>
//#import "LDSound.h"

// 主要使用AVAudioPlayer便可實現簡單的音效播放
// 這裡用到Categories整合AVAudioPlayer和一些自訂method去簡化操作
@implementation AVAudioPlayer (easyLoading)

- (id) initWithWav : (NSString *)fname {
	
	// 拚合出完整的bundle path（包含filename）
	NSString *soundPath = [[NSBundle mainBundle] pathForResource:fname ofType:@"wav"];

	//id snd = [[NSData alloc] initWithContentsOfFile : soundPath];
	//id tmp = [self initWithData: snd error:NULL];
	id tmp = [self initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:NULL];
	
//	[tmp prepareToPlay];
	
	return tmp;
	// NSURL *soundPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:fname ofType:@"wav"]];
	
//	theSound.delegate = self;
}

// 中斷正在播放的聲頻，倒回起點並播放
- (void) rewindAndPlay {
	
	[self stop];				// 停止正在播放的聲顏
	self.currentTime = 0.0;		// 回帶到最開始
	[self play];				// 重新播放

}
//- (void) playSound {
//	[theSound play];
//}

//- (void)dealloc {
//	[window release];
//	[glView release];
//	AudioServicesDisposeSystemSoundID(alertSoundID);
//	[super dealloc];
//}

@end
